package com.bw.product.controller;

import com.bw.common.core.domain.Result;
import com.bw.product.domain.DiscountCoupon;
import com.bw.product.domain.vo.SkuAttrDiscountCouponVo;
import com.bw.product.service.SkuAttrDiscountCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * sku与优惠券中间表
 */
@RestController
@RequestMapping("/SkuCoupon")
public class SkuAttrDiscountCouponController {
    @Autowired
    private SkuAttrDiscountCouponService skuAttrDiscountCouponService;


    /**
     * 根据商品skuId查询优惠券
     * @param skuId
     * @return
     */
    @GetMapping("/findSkuAttrDiscountCouponById/{skuId}")
    public Result<List<SkuAttrDiscountCouponVo>> selectSkuAttrDiscountCoupon(@PathVariable("skuId") Long skuId){
        List<SkuAttrDiscountCouponVo> skuAttrDiscountCoupon=skuAttrDiscountCouponService.selectSkuAttrDiscountCoupon(skuId);
        return Result.success(skuAttrDiscountCoupon);
    }


    /**
     * 用户领取优惠券
     */
    @GetMapping("/add/{discountCouponId}")
    public Result add(@PathVariable Integer discountCouponId){
        skuAttrDiscountCouponService.add(discountCouponId);
        Result<Object> result = Result.success();
        return result;
    }


    /**
     * 首页优惠券
     */
    @GetMapping("/list")
    public Result<List<SkuAttrDiscountCouponVo>> list(@RequestBody SkuAttrDiscountCouponVo skuAttrDiscountCouponVo){
        List<SkuAttrDiscountCouponVo> list= skuAttrDiscountCouponService.list(skuAttrDiscountCouponVo);
        return Result.success(list);
    }



}
